<template>
  <div>
    <header-bar></header-bar>
    <div class="bookView">
      <top-dowd-load></top-dowd-load>
      <h1>{{book.title}}</h1>
      <div class="content">
        <!--头部文字图片信息-->
        <div class="mc-text">
          <div class="mc-txt">
            <rating v-if="book.rating" :rating="book.rating"></rating>
            <span>人评价</span>
            <p>{{book.summary}}</p>
          </div>
          <div class="mc-img">
            <img :src="'https://images.weserv.nl/?url='+book.image" alt="" width="100" height="140">
          </div>
        </div>
        <!--购买-->
        <div class="buy">
          <a href="#">在豆瓣购买</a>
          <span>{{book.price}}元起</span>
        </div>
        <!--想看-->
        <div class="listen">
          <a href="#">想读</a>
          <a href="#">在读</a>
          <a href="#">读过</a>
        </div>
        <!--标签-->
        <div class="tags">
          <p>相关标签</p>
          <ul>
            <li v-for="(tag,t) in tags" :key="t.count">{{tag.name}}</li>
          </ul>
        </div>
      </div>
      <!--广告-->
      <div class="ad">
        <img src="../../assets/img/ad2.jpg" alt="" width="100%" height="96">
        <span class="ad-img">广告</span>
      </div>
      <down-load-app></down-load-app>
    </div>
  </div>
</template>

<script>
  import Rating from '../../public/Rating'
  import HeaderBar from '../HeaderBar'
  import TopDowdLoad from '../../public/TopDowdLoad'
  import DownLoadApp from '../../public/DownLoadApp'
  export default {
    name: 'BookView',
    data(){
      return{
        book:{},
        tags:[]
      }
    },
    components: {
      HeaderBar,
      TopDowdLoad,
      Rating,
      DownLoadApp
    },
    created() {
      const id = this.$route.params.bkid
          this.axios.get('/api/book/'+id)
            .then((res)=>{
              let book = res.data
              let tags = res.data.tags
              this.tags = tags
              this.book = book
              // console.log(tags)
            })
            .catch((err)=>console.log(err))
    }
  }
</script>

<style lang="scss">
  .bookView {
    margin-top: 47px;
    h1 {
      text-align: left;
      padding: 15px;
      margin: 15px 0 5px;
      font-size: 24px;
      line-height: 36px;
      word-break: break-all;
    }
    .content {
      padding: 0 15px;
      .mc-text {
        display: flex;
        line-height: 28px;
        .mc-txt {
          flex: 2;
          span {
            color: #aaa
          }
          .rating {
            display: inline-block;
            margin-right: 26px;
            span {
              color: #494949;
            }
          }
          p {
            color: #494949;
            margin-top: 15px;
            padding-right: 24px;
            font-size: 14px;
            line-height: 1.6;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp:10;
            overflow: hidden;
            text-align: justify;
          }
          .star-full {
            display: inline-block;
            width: 13px;
            height: 13px;
            background-image: url();
            background-size: cover;
          }

          .star-gray {
            display: inline-block;
            width: 13px;
            height: 13px;
            background-image: url();
            background-size: cover;
          }

          .star-half {
            display: inline-block;
            width: 13px;
            height: 13px;
            background-image: url();
            background-size: cover;
          }

          .average {
            padding-right: 8px;
            font-size: 15px;
          }
        }
        .mc-img {
          text-align: right;
          flex: 1;
        }
      }
    }
    .listen{
      display: flex;
      a{
        flex: 1;
        display: inline-block;
        height: 30px;
        width: 128px;
        margin:20px 10px;
        line-height: 30px;
        font-size: 15px;
        text-align: center;
        color: #ffb712;
        border: 1px solid #ffb712;
        border-radius: 3px;
      }
    }
    .tags{
      margin-bottom: 10px;
      p{
        color: #aaa;
        margin: 0 0 15px;
        font-size: 15px;
      }
      ul{
        li{
          display: inline-block;
          margin-right: 10px;
          padding: 5px 10px;
          border-radius: 15px;
          margin-bottom: 10px;
          font-size: 13px;
          border: 1px solid #42bd56;
          color: #42bd56;
          background-color: #effaf0;
        }
      }
    }
    .ad{
      line-height: 96px;
      height: 96px;
      position: relative;
      .ad-img{
        color: #aaa;
        position: absolute;
        bottom: 0;
        right: 0;
        display: inline-block;
        width: 34px;
        height: 23px;
        padding: 2px;
        line-height: 23px;
        text-align: center;
        background-color: rgba(0,0,0,0.4);
      }
    }
  }
  .buy{
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
    border-bottom: 1px solid #E8E8E8;
    border-top: 1px solid #E8E8E8;
    a{
      flex: 2;
      color: #42bd56;
      font-size: 15px;
    }
    span{
      flex: 1;
      text-align: right;
      color: #ccc;
      font-size: 14px;
    }
  }
</style>
